package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IContentService;
import com.mall.shopping.IHomeService;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.NavListResponse;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("shopping")
public class HomePageController {

    @Reference(timeout = 3000, check = false)
    IHomeService service;

    @Reference(timeout = 3000, check = false)
    IContentService contentService;

    @Reference(timeout = 3000, check = false)
    IProductCateService cateService;

    @Anoymous
//    @GetMapping("homepage")
    public ResponseData getHomePageInfo() {
        HomePageResponse respData = service.homepage();

        ResponseData response = new ResponseUtil().setData(respData.getPanelContentItemDtos());
        response.setTimestamp(System.currentTimeMillis());
        response.setMessage("success");
        return response;
    }

    @Anoymous
    @GetMapping("navigation")
    public ResponseData getNavigation() {
        NavListResponse result = contentService.queryNavList();

        ResponseData response = new ResponseUtil().setData(result.getPannelContentDtos());
        response.setTimestamp(System.currentTimeMillis());
        response.setMessage("success");
        return response;
    }

    @Anoymous
    @GetMapping("categories")
    public ResponseData getCategories(String sort) {
        AllProductCateResponse resultData = cateService.getAllProductCate(null);

        ResponseData response = new ResponseUtil().setData(resultData.getProductCateDtoList());
        response.setTimestamp(System.currentTimeMillis());
        response.setMessage("success");
        return response;
    }
}
